const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { ModuleFederationPlugin } = require('webpack').container;

module.exports = {
  entry: './src/index.tsx',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
  },
  externals: {
    react: 'react',
     'react-dom': 'ReactDOM',
  },
  resolve: {
    extensions: ['.tsx', '.ts', '.jsx', '.js'],
  },
  module: {
    rules: [
      {
        test: /\.(ts|tsx)$/,
        exclude: /node_modules/,
        use: 'babel-loader',
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: 'babel-loader',
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: './public/index.html',
    }),
    new ModuleFederationPlugin({
      name: 'sub_app',
      filename: 'remoteEntry.js',
      exposes: {
        './SubApp': './src/App', // 暴露子应用的模块
      },
      shared: {
        "react": {
          eager:true
        },
        "react-dom": {
          eager:true
        }
      }
    }),
  ],
  devServer: {
    port: 3001,
    open: true,
  },
};
